package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.InvitationContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.InvitationPresenter;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;
import com.ninetaildemonfox.zdl.socialproject.utils.dialog.ShareDialogActivity;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/24 10:05
 * 功能描述：邀请好友
 * 联系方式：1037438704@qq.com
 */

public class InvitationActivity extends BaseActivity implements InvitationContract {

    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_invitation)
    TextView textInvitation;
    @BindView(R.id.text_identification)
    TextView textIdentification;
    @BindView(R.id.text_vip)
    TextView textVip;
    @BindView(R.id.text_have)
    TextView textHave;
    @BindView(R.id.text_effective)
    TextView textEffective;
    private InvitationPresenter presenter;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_invitation;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        textCenter.setText("邀请好友");
        textRight.setText("活动规则");
        textRight.setVisibility(View.VISIBLE);
        imageleftFinish.setVisibility(View.VISIBLE);
        presenter = new InvitationPresenter(this, me);
        presenter.getInviteFriends(token);
    }

    @OnClick({R.id.image_left_finish, R.id.text_right, R.id.text_invitation})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_right:
                presenter.getActivityRul();
                break;
            case R.id.text_invitation:
//                是否vip 1否 2是           1未认证 2 已认证
                if (getSex.equals("1")) {
                    if (getVip.equals("1")) {
                        ToastUtil.show("成为会员才能邀请好友！");
                        return;
                    }
                } else {
                    if (getIdentification.equals("1")) {
                        ToastUtil.show("认证之后才能去邀请好友！");
                        return;
                    }
                }
                startActivity(new Intent(this, ShareDialogActivity.class));
                break;
            default:
        }
    }

    @Override
    public void Success(Map<String, String> data) {
        textIdentification.setText(data.get("identification") + "元现金奖励");
        textVip.setText(data.get("vip") + "元现金奖励");
        textHave.setText(data.get("have"));
        textEffective.setText(data.get("effective"));
    }

    @Override
    public void Failed(String msg) {

    }

    @Override
    public void showLoading() {
        WaitDialog.show(me, "数据加载中");
    }

    @Override
    public void ruleSuccess(Map<String, String> data) {
        String activity_rule = data.get("activity_rule");
        DetailsWebViewActivity.start(this, 1, activity_rule);
    }
}